package com.resource.authoritymanage.config;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.resource.authoritymanage.entity.TIdentifyRecordEntity;
import com.resource.authoritymanage.entity.TIdentifyRecordEntityExcel;
import com.resource.authoritymanage.mapper.TIdentifyRecordDao;
import lombok.Data;
import lombok.SneakyThrows;
import org.springframework.beans.BeanUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TIdentifyRecordEntityListener extends AnalysisEventListener<TIdentifyRecordEntityExcel> {

    private TIdentifyRecordDao tIdentifyRecordDao;
    public TIdentifyRecordEntityListener(TIdentifyRecordDao tIdentifyRecordDao) {
        this.tIdentifyRecordDao = tIdentifyRecordDao;
    }

    @SneakyThrows
    @Override
    public void invoke(TIdentifyRecordEntityExcel data, AnalysisContext context) {
        //调用方法添加数据库
        TIdentifyRecordEntity tIdentifyRecordEntity = new TIdentifyRecordEntity();
        tIdentifyRecordEntity.setUserName(data.getUserName());
        tIdentifyRecordEntity.setUserCode(data.getUserCode());
        tIdentifyRecordEntity.setLastLoginTime(data.getLastLoginTime());
        tIdentifyRecordEntity.setUserPrivilege(data.getUserPrivilege());
        tIdentifyRecordEntity.setUserType(data.getUserType());
        tIdentifyRecordEntity.setIsApply(data.getIsApply());
        tIdentifyRecordEntity.setGmtCreate(new Date());
        tIdentifyRecordEntity.setGmtModified(new Date());
        tIdentifyRecordDao.insert(tIdentifyRecordEntity);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {

    }
}
